import javax.servlet.ServletContext;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Properties;
@WebServlet("/contextservlet02")
public class ContextSerclet02  extends HttpServlet{
    @Override
    protected void service(HttpServletRequest req,HttpServletResponse resp) throws IOException {
        resp.setContentType("text/html;charset=UTF-8");
        ServletContext context = this.getServletContext();
       InputStream in = context.getResourceAsStream(
               "/WEB-INF/classes/db.properties");
       Properties prop = new Properties();
       prop.load(in);
       PrintWriter pw = resp.getWriter();
       pw.println("username的值：" +prop.getProperty("username")+
               "<br>");
       pw.println("username的值："+prop.getProperty("userpassword"));
    }
}